package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallCouponUserMapper;
import org.linlinjava.litemall.db.domain.LitemallCouponUser;
import org.linlinjava.litemall.db.domain.LitemallCouponUserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LitemallConponUserServiceImpl implements LitemallConponUserService {

    @Autowired
    LitemallCouponUserMapper mapper;

    @Override
    public List<LitemallCouponUser> getAll(Integer userId,Integer page, Integer limit,Short status, Integer couponId, String sort, String order) {
        LitemallCouponUserExample example = new LitemallCouponUserExample();
        example.setOrderByClause(sort+" "+order);
        LitemallCouponUserExample.Criteria criteria = example.createCriteria();
        if(couponId != null){
            criteria.andCouponIdEqualTo(couponId);
        }
        if(userId != null) {
            criteria.andUserIdEqualTo(userId);
        }

        if(status != null){
            criteria.andStatusEqualTo(status);
        }
        PageHelper.startPage(page,limit);
        return mapper.selectByExample(example);
    }
}
